package com.csproj.basic.repository.impl;

import com.csproj.basic.domain.PDA;
import com.csproj.basic.repository.custom.PDARepositoryCustom;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.HashMap;
import java.util.Map;

public class PDARepositoryImpl implements PDARepositoryCustom {
    @PersistenceContext
    private EntityManager em;

    public EntityManager getEm() {
        return em;
    }

    /**
     * 站点分页查询方法
     * @param map	参数
     * @param pageable		分页对象
     * @return
     */
    public Page<PDA> findPageList(Map<String, Object> map, Pageable pageable) {
        //拼hql
        String hql = " from PDA s where s.deletedFlag = 0 ";
        Map<String,Object> queryParams = new HashMap<>();

        String siteId = (String) map.get("siteId");
        if (StringUtils.isNotBlank(siteId)) {
            hql += " and s.siteId = :siteId and enableFlag = 1 ";
            queryParams.put("siteId",siteId);
        }

        String pdaNo = (String) map.get("pdaNo");
        if (StringUtils.isNotBlank(pdaNo)) {
            hql += " and s.pdaNo like :pdaNo";
            queryParams.put("pdaNo","%"+pdaNo+"%");
        }
        //查询
        Page<PDA> fieldList = query(hql, pageable, queryParams);
        //返回
        return fieldList;
    }

}
